const arr = [1, 2, 3, 4, 5];

// 值
for (let item of arr) {
  console.log(item); // 1 2 3 4 5
}

// 同上
// for (let item of arr.values()) {
//   console.log("values", item); // 1 2 3 4 5
// }

// 索引
for (let item of arr.keys()) {
  console.log("keys", item); // 0 1 2 3 4
}

// 索引和值
for (let [index, item] of arr.entries()) {
  console.log(index, " -- ", item); // 0 1 1 2 2 3 3 4 4 5 5
}

// for await
function getPromise(time) {
  return new Promise((resolve) =>
    setTimeout(
      () =>
        resolve({
          value: time,
          done: false,
        }),
      time
    )
  );
}
const promises = [getPromise(1000), getPromise(2000), getPromise(3000)];
for await (let item of promises) {
  console.log(item);
}
